#!/bin/bash

#########################
#                       # #
#     .---..-.-.-.      #   #
#     | |-'| | | |      #     #
#     `-'  `-----'      #       #
#  ~~~~~~Ver. 3~~~~~~   #_________#
# Parses /dev/urandom to generate #
#  passwords of various lengths.  # 
#       -- By Gary Locke          #
###################################

function genpass() {
truncate="tr -dc a-zA-Z0-9${spec}"
char8=`cat /dev/urandom| $truncate | fold -w 8 |head -1`
char12=`cat /dev/urandom| $truncate | fold -w 12 |head -1`
char16=`cat /dev/urandom| $truncate | fold -w 16 |head -1`
char20=`cat /dev/urandom| $truncate | fold -w 20 |head -1`
}

function echopass() {
echo "$char8 $char12 $char16 $char20" |\
    sed 's/[0O]/o/g' |\
    sed 's/[1l]/L/g' |\
    sed 's/I/i/g'
}

clear

if [[ -z $1 ]]; then
    printf "\n5 alphanumeric passwords:\n\n"
    for i in {1..5}; do genpass; echopass; done
    spec="!@#$%^&"
    printf "\n5 passwords using these special characters: !@#\$%%^&\n\n"
    for i in {1..5}; do genpass; echopass; done
else
    spec="$1"
    echo;echo "10 passwords using provided special character(s): $spec";echo
    for i in {1..10}; do genpass; echopass; done
fi
echo;exit
